﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_stp_auth_staff_list.ascx.vb" Inherits="Apps_Shares_Uc_stp_auth_staff_list" %>
<%--==============================BEGIN Filter==============================--%>
<table width="50%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#999999">
    <tr align="center" bgcolor="#99FFFF">
        <td colspan="2" bgcolor="#FFFFFF" class="th_data">
            ค้นหาข้อมูล
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            หน่วยงาน :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlDepartment' runat='server' AppendDataBoundItems="True" DataTextField="department_name"
                DataSourceID='ddlStpDepartmentSrc' DataValueField="department_code" AutoPostBack="True">
                <asp:ListItem Value="0" Text="หน่วยงาน"></asp:ListItem>
            </asp:DropDownList>
            <asp:ObjectDataSource ID="ddlStpDepartmentSrc" runat="server" SelectMethod="GetStpDepartmentByPrivilege"
                TypeName="CodeMatrix.Business.GenericData">
            </asp:ObjectDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            กลุ่มผู้ใช้งาน :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID="ddlGroupUser" runat="server" DataSourceID="ddlGroupUserSrc" DataTextField="group_user_name" DataValueField="group_user_code" AutoPostBack="true">
                <asp:ListItem Value="0">กลุ่มผู้ใช้งาน</asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="ddlGroupUserSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="select group_user_code = 0 , group_user_name = 'กลุ่มผู้ใช้งาน'
                                    union all
                                    select group_user_code , group_user_name
                                    from  group_user 
                                    where department_code = @department_code and group_user_status = 1 and group_user_code > 0">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddlDepartment" DefaultValue="0" Name="department_code"
                        PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            ผู้ใช้งาน :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID="ddlStaff" runat="server" DataSourceID="ddlStaffSrc" DataTextField="staff_name" DataValueField="staff_code">
                <asp:ListItem Value="0">ผู้ใช้งาน</asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="ddlStaffSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="select staff_no = '',staff_code = 0, staff_name = 'ผู้ใช้งาน'
                                    union all
                                    select
                                    staff_no,  
                                    staff_code , 
                                    cast(staff_no as varchar) + ' ' + staff_firstname + ' ' + staff_lastname as staff_name
                                    from  staff
                                    where @group_user_code = group_user_code and staff_status = 1 and staff_code > 0 order by staff_no">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddlGroupUser" DefaultValue="0" Name="group_user_code" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            สถานะ :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlStatus' runat="server">
                <asp:ListItem Text='สถานะ' Value='0'></asp:ListItem>
                <asp:ListItem Text='ใช้งาน' Value='1'></asp:ListItem>
                <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr align="center">
        <td colspan="2" bordercolor="#CCCCCC" class="td_data_end">
            <asp:Button ID='btnFilter' Text='<%$ Resources:Resource,BTN_SEARCH %>' runat='server' />
            <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
        </td>
    </tr>
</table>
<%--==============================END Filter==============================--%>
<div style="margin:5px;display:block;width:100%">&nbsp;</div>
<%--==============================BEGIN Gridview==============================--%>
<span class='component_caption'><asp:Literal ID='ltrCountView' runat='server' Text=''></asp:Literal></span>
<asp:ListView ID="gvDisplay" runat="server" DataSourceID="gvDisplaySrc" EnableModelValidation="True" DataKeyNames='staff_code'>
    <LayoutTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#999999" border="0" align="center"
            width="100%">
            <tbody>
                <tr bgcolor="#ff9999" align="center">
                    <td bgcolor="#ffffff" width="auto" class="th_data">
                        <asp:Image ID="staff_firstname" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort2' runat='server' CommandName='Sort' CommandArgument='staff_firstname'>ชื่อผู้ใช้งาน</asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="group_user_name" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort3' runat='server' CommandName='Sort' CommandArgument='group_user_name'>กลุ่มผู้ใช้งาน</asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="dept_hirachy" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort4' runat='server' CommandName='Sort' CommandArgument='dept_hirachy'>หน่วยงาน</asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="auth_staff_status" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort5' runat='server' CommandName='Sort' CommandArgument='auth_staff_status'>สถานะการใช้งาน</asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data col_delete">
                        <input id='icbHeader' type='checkbox' />ลบข้อมูล
                    </td>
                </tr>
                <asp:PlaceHolder ID='itemPlaceholder' runat='server' />
                <tr bgcolor="#ff9999" align="center">
                    <td id='tdPaging' bgcolor="#ffffff" class="td_data_end" colspan="4">
                        <%-- ====================== Data Pager ======================--%>
                        <asp:DataPager ID="paging" runat="server" PagedControlID="gvDisplay" PageSize='10'>
                            <Fields>
                                <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="false"
                                    ShowNextPageButton='false' ShowPreviousPageButton='false' FirstPageText='<<' />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="false"
                                    ShowNextPageButton='false' ShowPreviousPageButton='true' PreviousPageText='<' />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="false"
                                    ShowNextPageButton='true' ShowPreviousPageButton='false' NextPageText='>' />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="true"
                                    ShowNextPageButton='false' ShowPreviousPageButton='false' LastPageText='>>' />
                            </Fields>
                        </asp:DataPager>
                        <%-- ====================== Data Pager ======================--%>
                    </td>
                    <td bgcolor="#ffffff" class="td_data_end col_delete">
                        <asp:Button ID='btnDelete' runat='server' Text='ลบข้อมูล' OnClick='btnDelete_Click'
                            OnClientClick='<%$Resources:Resource,SCRIPT_CONFIRM_DELETE %>' />
                    </td>
                </tr>
            </tbody>
        </table>
    </LayoutTemplate>
    <EmptyDataTemplate>
        <br />
        <span class='star'>
            <center>
                ไม่พบข้อมูล</center>
        </span>
    </EmptyDataTemplate>
    <ItemTemplate>
        <tr >
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <a href='<%# "stp_auth_staff_fv.aspx?Edit=" & Eval("staff_code") & CodeMatrix.Business.GenericData.GetViewMode()  %> '><%#HttpUtility.HtmlEncode(Eval("staff_firstname") & " " & Eval("staff_lastname"))%></a>
            </td>
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <%#HttpUtility.HtmlEncode(Eval("group_user_name"))%>
            </td>
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <%#String.Format("{0}", CodeMatrix.Business.UserContext.PadLeft(Eval("master_department_level") - 1, "&nbsp;&nbsp;&nbsp;&nbsp;"))%>
                <%#HttpUtility.HtmlEncode(Eval("dept_hirachy"))%>&nbsp;
            </td>
            <td id='tdStatus' align="center" class="td_data f_status" bordercolor="#CCCCCC">
                <span><%#IIf(Eval("auth_staff_status").ToString() = "1", "ใช้งาน", "ไม่ใช้งาน")%></span>
            </td>
            <td align="center" class="td_data col_delete" bordercolor="#CCCCCC">
                <asp:CheckBox ID='icbItem' runat='server' />
            </td>
        </tr>
    </ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="gvDisplaySrc" runat="server" DeleteMethod="Delete" SelectMethod="GetData"
    TypeName="StpAuthenStaff">
    <DeleteParameters>
        <asp:Parameter DefaultValue="stp_auth_staff" Name="tbl" Type="String" />
        <asp:Parameter DefaultValue="staff_code" Name="pid" Type="String" />
        <asp:Parameter DefaultValue="" Name="cid" Type="String" />
    </DeleteParameters>
    <SelectParameters>
        <asp:Parameter Name="department_code" />
        <asp:Parameter Name="group_code" />
        <asp:ControlParameter ControlID="ddlStaff" ConvertEmptyStringToNull="False"
            Name="staff_code" PropertyName="SelectedValue" DefaultValue="0" Type="Int32" />
        <asp:ControlParameter ControlID="ddlStatus" Name="auth_staff_status" PropertyName="SelectedValue"
            DefaultValue="0" />
        <asp:SessionParameter Name="current_staff_code" SessionField="staff_code" />
    </SelectParameters>
</asp:ObjectDataSource>
<%-- ====================== Data Pager ======================--%>

<script type="text/javascript">
    matchTableCheckBox('icbHeader', 'icbItem');
    hideDeleteColumn();
    hilightInactive();
</script>

